<?php
/**
 * Created by PhpStorm.
 * User: zhang-hong
 * Date: 2017/4/25
 * Time: 15:20
 */
class DingshixunshidatauploadController extends Yaf_Controller_Abstract {

    function indexAction()
    {
        $request = $this->getRequest();
        $data = $request->getPost('data', '');
        $yiyuan_id = $request->getPost("yiyuan_id","");
        if($yiyuan_id === "" )
        {
            Utility::apiJsonError(20028, '请输入医院ID');
        }
        elseif(!ctype_digit("$yiyuan_id"))
        {
            Utility::apiJsonError(20027, '医院ID必须是整型');
        }
        $compression_http_data = $request->getPost('compression_http_data', 'off');
        $data = Utility::uncompress($data, $compression_http_data);
        if (!$data) {
            Utility::apiJsonError('10010', '请上传数据!');
        }
        $data = json_decode($data, true);
        if (empty($data)) {
            Utility::apiJsonError('10010', '数据为空或者数据格式不正确');
        }else{

            foreach ($data as $key=>$item)
            {
                $data[$key]['yiyuan_id'] = $yiyuan_id;
                $data[$key]['modify_time'] = date("Y-m-d H:i:s");
            }
        }

        list($insert_id, $rows) = Utility::multiInsert('dingshi_xunshi_zhixing',$data);
        if($rows > 0)
        {
            $result = ['error' => 200, 'msg' => ""];
            Utility::apiJsonResultExtends($result);
        }else{
            Utility::apiJsonError('10011', '数据为空或者数据格式不正确');
        }
    }
}